package com.yunqiao.admin.modules.api.controller;

import com.yunqiao.common.utils.PageUtils;
import com.yunqiao.common.utils.R;
import com.yunqiao.service.api.RedPacketService;
import com.yunqiao.service.api.entity.RedPacketEntity;
import com.yunqiao.service.api.vo.RedPacketEntityVo;
import com.yunqiao.service.api.vo.RedPacketVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 红包表
 *
 * @author Crocutax
 * @email wangxw725@163.com
 * @date 2019-03-02 15:03:56
 */
@RestController
@RequestMapping("api/redpacket")
public class RedPacketController {

    @Autowired
    private RedPacketService redPacketService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("api:redpacket:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = redPacketService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("api:redpacket:info")
    public R info(@PathVariable("id") Integer id){
        RedPacketVo redPacket = redPacketService.details(id);
        return R.ok().put("redPacket", redPacket);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("api:redpacket:save")
    public R save(@RequestBody RedPacketEntityVo redPacket){
        redPacketService.saveRed(redPacket);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("api:redpacket:update")
    public R update(@RequestBody RedPacketEntity redPacket){
        redPacketService.updateById(redPacket);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("api:redpacket:delete")
    public R delete(@RequestBody Integer[] ids){
        redPacketService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
